package com.ruoyi.procurementmanagement.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.procurementmanagement.domain.PurchasePriceHistory;
import com.ruoyi.procurementmanagement.service.IPurchasePriceHistoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购价格历史Controller
 * 
 * @author ruoyi
 * @date 2025-05-27
 */
@RestController
@RequestMapping("/procurementmanagement/history")
public class PurchasePriceHistoryController extends BaseController
{
    @Autowired
    private IPurchasePriceHistoryService purchasePriceHistoryService;

    /**
     * 查询采购价格历史列表
     */
    @PreAuthorize("@ss.hasPermi('procurementmanagement:history:list')")
    @GetMapping("/list")
    public TableDataInfo list(PurchasePriceHistory purchasePriceHistory)
    {
        startPage();
        List<PurchasePriceHistory> list = purchasePriceHistoryService.selectPurchasePriceHistoryList(purchasePriceHistory);
        return getDataTable(list);
    }

    /**
     * 导出采购价格历史列表
     */
    @PreAuthorize("@ss.hasPermi('procurementmanagement:history:export')")
    @Log(title = "采购价格历史", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PurchasePriceHistory purchasePriceHistory)
    {
        List<PurchasePriceHistory> list = purchasePriceHistoryService.selectPurchasePriceHistoryList(purchasePriceHistory);
        ExcelUtil<PurchasePriceHistory> util = new ExcelUtil<PurchasePriceHistory>(PurchasePriceHistory.class);
        util.exportExcel(response, list, "采购价格历史数据");
    }

    /**
     * 获取采购价格历史详细信息
     */
    @PreAuthorize("@ss.hasPermi('procurementmanagement:history:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(purchasePriceHistoryService.selectPurchasePriceHistoryById(id));
    }

    /**
     * 新增采购价格历史
     */
    @PreAuthorize("@ss.hasPermi('procurementmanagement:history:add')")
    @Log(title = "采购价格历史", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PurchasePriceHistory purchasePriceHistory)
    {
        return toAjax(purchasePriceHistoryService.insertPurchasePriceHistory(purchasePriceHistory));
    }

    /**
     * 修改采购价格历史
     */
    @PreAuthorize("@ss.hasPermi('procurementmanagement:history:edit')")
    @Log(title = "采购价格历史", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PurchasePriceHistory purchasePriceHistory)
    {
        return toAjax(purchasePriceHistoryService.updatePurchasePriceHistory(purchasePriceHistory));
    }

    /**
     * 删除采购价格历史
     */
    @PreAuthorize("@ss.hasPermi('procurementmanagement:history:remove')")
    @Log(title = "采购价格历史", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(purchasePriceHistoryService.deletePurchasePriceHistoryByIds(ids));
    }
}
